import { axiosMock, delayFn, randArrItem } from '@/services/axiosMock'
import { ICusEmailTemplateInfo, IEmailTemplateInfo } from '../interface'

const htmlBody = `<h1>Welcome,Client {{Client_Name}}!</h1>
<p>Thanks for use Order ID {{ Order_ID }}. We’re thrilled to have you on board. To get the most out of {{ Shipping_Method }}, do this primary next step:</p>
<!-- Action -->
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"></td>
     <td class="attributes_item"><strong>Estimated Delivery Date:</strong> {{Estimated_Delivery_Date}}</td>
     <td class="attributes_item"><strong>Destination:</strong> {{Destination}}</td>
  </tr>
</table>
<p>For reference, here's your login information:</p>
<table class="attributes" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td class="attributes_content">
      <table width="100%" cellpadding="0" cellspacing="0">
        <tr>
          <td class="attributes_item"><strong>FBA ID:</strong> {{FBA_ID}}</td>
        </tr>
        <tr>
          <td class="attributes_item"><strong>Estimated Delivery Window:</strong> {{Estimated_Delivery_Window}}</td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<p>You've started a {{route_time}} day trial. You can upgrade to a paying account or cancel any time.</p>
<table class="attributes" width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td class="attributes_content">
      <table width="100%" cellpadding="0" cellspacing="0">
        <tr>
          <td class="attributes_item"><strong>Carton Quantity:</strong> {{Carton_Quantity}}</td>
        </tr>
         <tr>
          <td class="attributes_item"><strong>Route Time:</strong> {{Route_Time}}</td>
        </tr>
        <tr>
          <td class="attributes_item"><strong>Routing Description:</strong> {{Routing_Description}}</td>
        </tr>
      </table>
    </td>
  </tr>
</table>`

axiosMock('default', mock => {
  // 获取模板信息
  mock.onPost(`/tmsapi/customer_notice/getTemplateInfo`).reply(
    delayFn(600, () => {
      return {
        success: true,
        data: {
          templateId: 'xxx',
          title: randArrItem(['模板标题模板标题模板标题模板标题模板标题'], 0.1),
          type: randArrItem(['模板类型'], 0.1),
          subject: randArrItem(['Welcome to {{Routing_Title}}']),
          htmlBody,
          dynamicFields: [{ key: 'xxx', value: 'xxx' }],
        } satisfies IEmailTemplateInfo,
      }
    }),
  )

  // 获取自定义模板信息
  mock.onPost(`/tmsapi/customer_notice/getCustomTemplateInfo`).reply(
    delayFn(600, () => {
      return {
        success: true,
        data: {
          templateId: 'xxx',
          title: randArrItem(['模板标题模板标题模板标题模板标题模板标题'], 0.1),
          type: randArrItem(['模板类型'], 0.1),
          subject: `Welcome to {{Routing_Title}}`,
          htmlBody: `<p>Thanks for trying routing_description :{{ Routing_Description }}</p>`,
        } satisfies ICusEmailTemplateInfo,
      }
    }),
  )

  // 发送模板邮件
  mock.onPost(`/tmsapi/template/sendEmailByTemplate`).reply(
    delayFn(600, () => {
      return {
        success: true,
      }
    }),
  )

  // 标记路由邮件已发送
  mock.onPost(`/tmsapi/customer_notice/finishNotice`).reply(
    delayFn(600, () => {
      return {
        success: true,
      }
    }),
  )
})
